/**
 * useRequest 基本使用
 */
import React from 'react';
import { useRequest } from 'ahooks';

function getUsername() {
  return new Promise(resolve => {
    setTimeout(() => {
      resolve({ name: '小明' });
    }, 1200);
  });
}

export default () => {
  const { data, error, loading } = useRequest(getUsername);

  if (error) {
    return <div>failed to load</div>;
  }
  if (loading) {
    return <div>loading...</div>;
  }
  return <div>Username: {data.name}</div>;
};
